package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wechat.domain.Appointment;
import com.ruoyi.wechat.service.IAppointmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 营地预约Controller
 * 
 * @author ruoyi
 * @date 2024-07-30
 */
@Api(value = "营地预约", tags = {"营地预约"})
@RestController
@RequestMapping("/wechat/appointment")
public class WxAppointmentController extends BaseController
{
    @Autowired
    private IAppointmentService appointmentService;


    @ApiOperation("查询营地预约列表总数")
    @GetMapping("/listInfoNumber")
    public AjaxResult listInfoNumber()
    {

        List<Integer> list = appointmentService.listInfoNumber();
        List<BigDecimal> appointmentServiceSalesMoney = appointmentService.getSalesMoney();
        Collections.reverse(appointmentServiceSalesMoney);
        List<List> objects = new ArrayList<>();
        objects.add(list);
        objects.add(appointmentServiceSalesMoney);
        return new AjaxResult(200,"获取成功",objects);
    }

    /**
     * 查询营地预约列表
     */
    @ApiOperation("查询营地预约列表")
    @GetMapping("/list")
    public TableDataInfo list(Appointment appointment)
    {
//        startPage();
        List<Appointment> list = appointmentService.selectAppointmentList(appointment);
        return getDataTable(list);
    }




    /**
     * 获取营地预约详细信息
     */
    @ApiOperation("获取营地预约详细信息")
    @GetMapping(value = "/{appointId}")
    public AjaxResult getInfo(@PathVariable("appointId") String appointId)
    {
        return success(appointmentService.selectAppointmentByAppointId(appointId));
    }

    /**
     * 新增营地预约
     */
    @ApiOperation("新增营地预约")
    @Log(title = "营地预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Appointment appointment)
    {
        return toAjax(appointmentService.insertAppointment(appointment));
    }

    /**
     * 修改营地预约
     */
    @ApiOperation("修改营地预约")
    @Log(title = "营地预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Appointment appointment)
    {
        return toAjax(appointmentService.updateAppointment(appointment));
    }

    /**
     * 删除营地预约
     */
    @ApiOperation("删除营地预约")
    @Log(title = "营地预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appointIds}")
    public AjaxResult remove(@PathVariable String[] appointIds)
    {
        return toAjax(appointmentService.deleteAppointmentByAppointIds(appointIds));
    }
}
